import axios from '@/libs/api.request'
import config from '@/config'

export const getAccountTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'UserService.view',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editAccountRecord = async (playload) => {
  let module_name = 'UserService.add'
  if (playload.id && playload.id !== '') {
    module_name = 'UserService.update'
  }
  const data = {
    module: module_name,
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const editSysAccountRecord = async (playload) => {
  let module_name = 'AdminService.adminUserAdd'
  if (playload.id && playload.id !== '') {
    module_name = 'UserService.update'
  }
  const data = {
    module: module_name,
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getRoleTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SystemService.viewGroup',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const getViewRoleTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SystemService.viewRole',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const getRoleInfo = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SystemService.groupInfo',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editRoleRecord = async (playload) => {
  // let module_name = 'SystemService.addGroup'
  // if (playload.id && playload.id !== '') {
  //   module_name = 'SystemService.updateGroup'
  // }
  const data = {
    module: 'SystemService.groupRoleChange',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getBannerTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SystemService.banners',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editBannerRecord = async (playload) => {
  let module_name = 'SystemService.addBanner'
  if (playload.id && playload.id !== '') {
    module_name = 'SystemService.updateBanner'
  }
  const data = {
    module: module_name,
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const deleteBannerRecord = async (playload) => {
  const data = {
    module: 'SystemService.deleteBanner',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getConfigTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SystemService.viewConfig',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editConfigRecord = async (playload) => {
  const data = {
    module: 'SystemService.updateConfig',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getMessageTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SystemService.messageView',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editMessageRecord = async (playload) => {
  const data = {
    module: 'SystemService.messageRead',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const editBasicRecord = async (playload) => {
  const data = {
    module: 'SystemService.updateMultiConfig',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getSysParamsTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'AdminService.userConfigs',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editSysConfigRecord = async (playload) => {
  const data = {
    module: 'AdminService.userConfigUpdate',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

// export const editCustomerRecord = async (playload) => {
//   let module_name = 'ContentService.add'
//   if (playload.id && playload.id !== '') {
//     module_name = 'ContentService.update'
//   }
//   const data = {
//     module: module_name,
//     ...playload
//   }
//   const resp = await axios.request({
//     url: config.postUrl,
//     data,
//     method: 'post'
//   })
//   return resp
// }
